package com.projectsquirrel;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;



/* 
 * @Author Daniel
 * 
 */
public class Observation {
	//----Auto Generated----//
	private static Observation instance = null;
	private String name = ""; //should be auto generated -ds
	private static Date createdDate = null;
	private int day = 0; //assume to be error free
	private int month = 0; //assume to be error free
	private int year = 0; //assume to be error free
	private int minute = 0; //assume to be error free
	private int hour = 0; //assume to be error free
	private String amPm; //true if PM
	private String zipCode = "";
	private double latitude = 0.0; 
	private double longitude = 0.0;
	private String email = ""; // auto-generated passed into constructor, we can assume it to be error free
	//----End Auto Generated----//
	
	//--screen1 method--
	private String numOfGraySquirrels = "";
	private String numOfFoxSquirrels = "";
	private String newSite = "";
	private String usedDifferentSite = "";
	private String numOfSqurChange = "";
	private String generalComments = ""; // comment section
	//--end screen1 method--
	
	//--screen2 method--
	private String setting = "";
	private String nutTrees = "";
	private String seedTrees = "";
	private String fruitTrees = "";
	private String tinyTrees = "";
	private String conTrees = "";
	private String otherTreeComments = ""; // comment section
	//--end screen2 method--
	
	//--screen3Feed method--
	private String feedFromBirdFeeder = "";
	private String feedFromHandouts = "";
	private String feedFromGarbage = "";
	private String feedFromTrees = "";
	private String feedFromOther = "";
	private String feedFromComments = ""; // comment section
	//--end screen3Feed method--
	
	//--screen3Num method--
	private String numOfSiteDogs = "";
	private String numOfSiteCats = "";
	private String numOfSiteCoyotes = "";
	private String numOfSiteHawks = "";
	private String numOfSitePGrain = "";
	//--end screen3Num method--
	
	
	protected Observation(String userEmail){
		Calendar calendar = new GregorianCalendar();
	    calendar.setTime(new Date());
	    createdDate = new Date();
		day = calendar.get(Calendar.DAY_OF_MONTH);
		month = calendar.get(Calendar.MONTH);
		year = calendar.get(Calendar.YEAR);
		minute = createdDate.getMinutes();
		hour = createdDate.getHours();
		
		
		if(hour>=12){
			amPm = "PM";
			
		}
		else{
			amPm = "AM";
		}
		
		email = userEmail;
		name = createdDate.toString(); 
	}
	public static Observation getInstance( String email){
		if(instance==null){
			instance = new Observation(email);
		}
		return instance;
		
	}
	public static void resetInstance()
	{
		instance = null;
	}
	public String getName(){
		return name;
	}
	public void setZip(String Zip){
		zipCode = Zip;
	}
	public String getDate(){
		return month+1+"-"+day+"-"+year;
	}
	public String getTime(){
		int htemp = hour;
		if(hour > 12){
			htemp -= 12;
		}
		else if(hour==0){
			htemp+=12;
		}
		return htemp+":"+pad(minute)+amPm;
	}
	public void setDate(int Day, int Month, int Year){
		day = Day;
		month = Month;
		year = Year;
	}
	public void setTime(int Hour, int Minute){
		if(Hour >12){
			hour = Hour;
			hour-=12;
			amPm = "PM";
		}
		if(Hour==12){
			amPm ="PM";
			hour = Hour;
		}
		else{
			amPm = "AM";
			hour = Hour;
		}
		
		
		minute = Minute;
	}
	public void setNumOfGray(String numOfGray){
		if(numOfGray.equals("")) numOfGraySquirrels = "0";
		else numOfGraySquirrels = numOfGray;
	}
	public void setLatLong(double lat, double Longitude){
		latitude = lat;
		longitude = Longitude;
	}
	public void setNumOfFox(String numOfFox){
		if(numOfFox.equals("")) numOfFoxSquirrels = "0";
		else numOfFoxSquirrels = numOfFox;
	}
	public boolean setUsingSameSite(String new_Site){
		if(new_Site.equals("YES")||new_Site.equals("NO")){
			newSite = new_Site;
			return true;
		}
		return false;
	}
	public String getUsingSameSite(){
		return newSite;
	}
	public boolean setUsingDifSite(String usedDifSite){
		if(usedDifSite.equals("YES")||usedDifSite.equals("NO")){
			usedDifferentSite = usedDifSite;
			return true;
		}
		return false;
	}
	public void setNumOfSqurrelChange(String numOfSquirrelChange){
		numOfSqurChange = numOfSquirrelChange;
	}
	public void setGeneralComments(String comment){								
		generalComments = comment;
		
	}
	public void setSetting(String setting){
		this.setting = setting;
	}
	public void setTreeComments(String comment){								
		otherTreeComments = comment;
		
	}
	public void setFeedComments(String comment){								
		feedFromComments = comment;
		
	}
 	private static String pad(int c) {
	        if (c >= 10)
	            return String.valueOf(c);
	        else
	            return "0" + String.valueOf(c);
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 * 
	 * This lovely method converts all class data into a string which can be directly ported to an output file
	 * This format was based upon the TA's guidelines.
	 * @Author Daniel
	 */
	public String toString(){
		/*Day, "[DD]"
		Month, "[MM]"
		Year, "[YYYY]"
		Hour, "[HH]"
		Minute, "[MM]"
		AMPM, "[XM]"
		ZIP, "[XXXXX-XXXX]"
		LATITUDE, "[example: 41.86962474217837]"
		LONGITUDE, "[example: -87.6494836807251]"
		EMAIL, "[XXX@XX.XXX]"
		NUM_GRAY_SQUIRRELS, "[X]"
		NUM_FOX_SQUIRRELS, "[X]"
		SETTING, "[X, where X is one of: SINGLE_FAM, MULT_FAM, HIGHRISE, PARK, NATURE, GARDEN, COMMER, SCHOOL, LOT, CEMETERY, FARM]"
		NUT_TREES, "[X, where X is one of: YES, NO, UNSURE]"
		SEED_TREES, "[X, where X is one of: YES, NO, UNSURE]"
		FRUIT_TREES, "[X, where X is one of: YES, NO, UNSURE]"
		TINY_TREES, "[X, where X is one of: YES, NO, UNSURE]"
		CON_TREES, "[X, where X is one of: YES, NO, UNSURE]"
		OTHER_TREES, "[X, where X is a string]"
		FEED_BIRD_FEEDER, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
		FEED_HANDOUTS, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
		FEED_GARBAGE, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
		FEED_TREES, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
		FEED_OTHER, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
		FEED_OTHER_DETAILS, "[X, where X is a string]"
		NUM_SQUIRREL_CHANGE, "[X, where X is one of SAME, INCREASED, DECREASED]"
		SITE_DOGS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
		SITE_CATS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
		SITE_COYOTES, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
		SITE_HAWKS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
		SITE_GRAIN, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
		THIS_NEW_SITE, "[X, where X is one of YES, NO]"
		USED_DIFFERENT_SITE, "[X, where X is one of YES, NO]"
		COMMENTS, "[X, where X is a string]"*/
		String ret = 
			"Day, ["+day+"]\n"
			+"Month, ["+(month+1)+"]\n"
			+"Year, ["+year+"]\n"
			+"Hours, ["+hour+"]\n"
			+"Minute, ["+minute+"]\n"
			+"AMPM, ["+amPm+"]\n"
			+"ZIP, ["+zipCode+"]\n"
			+"LATITUDE, ["+latitude+"]\n"
			+"LONGITUDE, ["+longitude+"]\n"
			+"EMAIL, ["+email+"]\n"
			+"NUM_GRAY_SQUIRRELS, ["+numOfGraySquirrels+"]\n"
			+"NUM_FOX_SQUIRRELS, ["+numOfFoxSquirrels+"]\n"
			+"SETTING, ["+setting+"]\n"
			+"NUT_TREES, ["+nutTrees+"]\n"
			+"SEED_TREES, ["+seedTrees+"]\n"
			+"FRUIT_TREES, ["+fruitTrees+"]\n"
			+"TINY_TREES, ["+tinyTrees+"]\n"
			+"CON_TREES, ["+conTrees+"]\n"
			+"OTHER_TREES, ["+otherTreeComments+"]\n"
			+"FEED_BIRD_FEEDER, ["+feedFromBirdFeeder+"]\n"
			+"FEED_HANDOUTS, ["+feedFromHandouts+"]\n"
			+"FEED_GARBAGE, ["+feedFromGarbage+"]\n"
			+"FEED_TREES, ["+feedFromTrees+"]\n"
			+"FEED_OTHER, ["+feedFromOther+"]\n"
			+"FEED_OTHER_DETAILS, ["+feedFromComments+"]\n"
			+"NUM_SQUIRREL_CHANGE, ["+numOfSqurChange+"]\n"
			+"SITE_DOGS, ["+numOfSiteDogs+"]\n"
			+"SITE_CATS, ["+numOfSiteCats+"]\n"
			+"SITE_COYOTES, ["+numOfSiteCoyotes+"]\n"
			+"SITE_HAWKS, ["+numOfSiteHawks+"]\n"
			+"SITE_GRAIN, ["+numOfSitePGrain+"]\n"
			+"THIS_NEW_SITE, ["+newSite+"]\n"
			+"USED_DIFFERENT_SITE, ["+usedDifferentSite+"]\n"
			+"COMMENTS, ["+generalComments+"]\n";
		return ret;
	}
	public void setNutTree(String string) {
		nutTrees = string;
	}
	public void setSeedTree(String string) {
		seedTrees = string;
	}
	public void setFruitTree(String string) {
		fruitTrees = string;
	}
	public void setTinyTree(String string) {
		tinyTrees = string;
	}
	public void setConeTree(String string) {
		conTrees = string;
	}
	public void setBirdFeed(String string) {
		feedFromBirdFeeder = string;
	}
	public void setHumanFeed(String string) {
		feedFromHandouts = string;
	}
	public void setGarbageFeed(String string) {
		feedFromGarbage = string;
	}
	public void setPlantFeed(String string) {
		feedFromTrees = string;
	}
	public void setOtherFeed(String string) {
		feedFromOther = string;
	}
	public void setCats(String string) {
		numOfSiteDogs = string;		
	}
	public void setDogs(String string) {
		numOfSiteCats = string;				
	}
	public void setCoyotes(String string) {
		numOfSiteCoyotes = string;		
	}
	public void setHawks(String string) {
		numOfSiteHawks = string;				
	}
	public void setPGrain(String string) {
		numOfSitePGrain = string;		
	}

	public int getDay()
	{
		return day;
	}
	public int getMonth()
	{
		return month;
	}
	public int getYear()
	{
		return year;
	}
	public int getMinute()
	{
		return minute;
	}
	public int getHour()
	{
		return hour;
	}
	public String getAMPM()
	{
		return amPm;
	}
	public String getZIP()
	{
		return zipCode;
	}
	public double getLatitude()
	{
		return latitude;
	}
	public double getLongitude()
	{
		return longitude;
	}
	public String getEmail()
	{
		return email;
	}
	public String getNumOfGraySquirrels()
	{
		return numOfGraySquirrels;
	}
	public String getNumOfFoxSquirrels()
	{
		return numOfFoxSquirrels;
	}
	public String getNewSite()
	{
		return newSite;
	}
	public String getUsedDifferentSite()
	{
		return usedDifferentSite;
	}
	public String getNumOfSqurChange()
	{
		return numOfSqurChange;
	}
	public String getGeneralComments()
	{
		return generalComments;
	}
	public String getSetting()
	{
		return setting;
	}
	public String getNutTrees()
	{
		return nutTrees;
	}
	public String getSeedTrees()
	{
		return seedTrees;
	}
	public String getFruitTrees()
	{
		return fruitTrees;
	}
	public String getTinyTrees()
	{
		return tinyTrees;
	}
	public String getConTrees()
	{
		return conTrees;
	}
	public String getOtherTreeComments()
	{
		return otherTreeComments;
	}
	public String getFeedFromBirdFeeder()
	{
		return feedFromBirdFeeder;
	}
	public String getFeedFromHandouts()
	{
		return feedFromHandouts;
	}
	public String getFeedFromGarbage()
	{
		return feedFromGarbage;
	}
	public String getFeedFromTrees()
	{
		return feedFromTrees;
	}
	public String getFeedFromOther()
	{
		return feedFromOther;
	}
	public String getFeedFromComments()
	{
		return feedFromComments;
	}
	public String getNumOfSiteDogs()
	{
		return numOfSiteDogs;
	}
	public String getNumOfSiteCats()
	{
		return numOfSiteCats;
	}
	public String getNumOfSiteCoyotes()
	{
		return numOfSiteCoyotes;
	}
	public String getNumOfSiteHawks()
	{
		return numOfSiteHawks;
	}
	public String getNumOfSitePGrain()
	{
		return numOfSitePGrain;
	}

	/*
	 * Read From File to populate an observation:
	 * int i = 0;
		
		while(!fileNames[i].equals(null)){
			FileInputStream fileStream = new FileInputStream(fileNames[i]);
			openFileInput(fileNames[i]);
			i++;
		}
		public void readFromFile(String filename){
		try {
			FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
			fos.write(string.getBytes());
			fos.close();
		} 
		catch (java.io.FileNotFoundException e) {
		    // do something if the myfilename.txt does not exits
		  }
	}
	 * 
	 */
}
